package com.zhujy.huawei;

import java.util.Scanner;

public class CompareJoker {
	public static void compare(String s) {
		String[] two_str = s.split("-");
		String[] left_str = two_str[0].split(" ");
		String[] right_str = two_str[1].split(" ");
		String order = "345678910JQKA2";
		if(s.contains("joker JOKER")) {
			System.out.println("joker JOKER");
			return;
		}
		if(left_str.length == 4 && right_str.length != 4) {
			System.out.println(two_str[0]);
			return;
		}else if(left_str.length !=4 &&right_str.length == 4) {
			System.out.println(two_str[1]);
			return;
		}else if(left_str.length == right_str.length){
			String res = order.indexOf(left_str[0]) >  order.indexOf(right_str[0])?two_str[0]:two_str[1];
			System.out.println(res);
			return;
		}else {
			System.out.println("ERROR");
			return;
		}
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNext()) {
			String str = in.nextLine();
			compare(str);
		}
		in.close();
	}
}
